<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .progress {
        border: solid;
      }
      .progress > div {
        height: 20px;
        /* margin: 5px; */
        width: 0%;
        background-color: blue;
        color: white;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div class="progress">
      <div id="progressBar"></div>
    </div>

    <script>
      const xhr = new XMLHttpRequest();
      const progressBar = document.getElementById("progressBar");
      xhr.open("GET", "http://127.0.0.1:8081/video ");
      // **** **** **** **** **** **
      xhr.onprogress = function (e) {
        // loaded 已下载
        // total 文件大小
        // console.log(`${e.loaded} / ${e.total}=${e.loaded / e.total}`);
        const w = (e.loaded / e.total) * 100 + "%";
        progressBar.style.width = w;
      };

      xhr.onload = function () {
        console.log("success");
        progressBar.innerHTML = "success";
      };
      xhr.onerror = function () {
        console.log("error");
      };
      xhr.send();
    </script>
  </body>
</html>
